﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Luna
{
	public static class XmlNodeExtension
	{
		public static string getAttribute(this XmlNode node, string name) {
			XmlAttribute attr = node.Attributes[name];
			return attr != null ? attr.Value : default(string);
		}

		public static string getAttribute(this XmlNode node, string name, string defaultValue) {
			XmlAttribute attr = node.Attributes[name];
			return attr != null ? attr.Value : defaultValue;
		}

		public static void setAttribute(this XmlNode node, string name, object value) {
			XmlAttribute attr = node.Attributes[name];
			if (attr == null) attr = node.Attributes.Append(node.OwnerDocument.CreateAttribute(name));
			attr.Value = value.ToString();
		}
	}
}
